<template>
    <div id="app">
     <!-- 搜索框 -->
     <Search ></Search>
 
     <!-- 轮播图 -->
     <Banner></Banner>
 
     <!-- 排序列表 -->
     <Sort :dainIndex="dainIndex" @deliverIndex="changelist" ></Sort>
 
     <!-- 商品列表 -->
     <List :list="list"></List>
 
   </div>
 </template>
 
 <script>

import { banner, shop_list, tuan_list, user_login } from '../../utils/api'

export default {
   data(){
     return {
       // 用来保存当前点击的分类下标
       dainIndex:0,
       list:[],
       ban:[]
     }
   },
   mounted(){
       shop_list().then((res)=>{
       console.log(res.data);
       this.list = res.data.list;
       })
       banner().then((res)=>{
        this.ban = res.data.list;
       })
   },
   methods:{
     changelist(index){
       this.dainIndex = index;  
     // 当点击综合排序按评分排
       if (index == 0) {
         // 当点击综合排序按照评分排序
         this.list.sort((a, b) => {
           return a.wmPoiScore - b.wmPoiScore;
         });
         // 当点击距离最近按距离排序
       } else if (index == 1) {
         this.list.sort((a, b) => {
           return (
             parseInt(b.minPriceTip.slice(4))-parseInt(a.minPriceTip.slice(4))
           );
         });
         // 当点击销量最高按销量排序
       } else if (index == 2) {
         this.list.sort((a, b) => {
           return (
             parseInt(b.monthSalesTip.slice(2))-parseInt(a.monthSalesTip.slice(2))
           );
         });
         // 点击筛选按时间排序
       } else if (index == 3) {
         this.list.sort((a, b) => {
           // deliveryTimeTip
           return (
               // console.log(b.deliveryTimeTip.slice(0,2)),
             parseInt(b.deliveryTimeTip.slice(0,2))-parseInt(a.deliveryTimeTip.slice(0,2))
           );
         });
       }
     },
   },
     }
 
 </script>
 
 <style lang="scss" >
 *{
   margin: 0;
   padding: 0;
 }
 
 
 </style>
 